package com.vict.bean.appversion.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.vict.entity.AppVersion;
import com.vict.enums.app.Platform;
import com.vict.framework.fastjsonserializer.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.sql.Timestamp;
import java.util.Optional;

@Data
public class AppVersionVO {

    @JSONField(serialize = false, deserialize = false)
    private AppVersion appVersion;

    @ApiModelProperty("id")
    @JSONField(serializeUsing = LongSerializer.class, deserializeUsing = LongDeserializer.class)
    public Long getId() {
        return Optional.ofNullable(appVersion).map(o-> o.getId()).orElse(null);
    }

    @ApiModelProperty("平台 Android IOS")
    @JSONField(serializeUsing = EnumSerializer.class, deserializeUsing = EnumDeserializer.class)
    public Platform getPlatform() {
        return Optional.ofNullable(appVersion).map(o-> o.getPlatform()).orElse(null);
    }

    @ApiModelProperty("版本号")
    public String getVersionStr() {
        return Optional.ofNullable(appVersion).map(o-> o.getVersionStr()).orElse(null);
    }

    @ApiModelProperty("发布时间")
    @JSONField(serializeUsing = TimestampSerializer.class, deserializeUsing = TimestampDeserializer.class)
    public Timestamp getReleaseTime() {
        return Optional.ofNullable(appVersion).map(o-> o.getReleaseTime()).orElse(null);
    }

    @ApiModelProperty("更新内容,功能介绍")
    public String getInfo() {
        return Optional.ofNullable(appVersion).map(o-> o.getInfo()).orElse(null);
    }

    @ApiModelProperty("更新包")
    public String getFileUrl() {
        return Optional.ofNullable(appVersion).map(o-> o.getFileUrl()).orElse(null);
    }

    @ApiModelProperty("状态, test release")
    @JSONField(serializeUsing = EnumSerializer.class, deserializeUsing = EnumDeserializer.class)
    public AppVersion.Status getStatus(){
        return Optional.ofNullable(appVersion).map(o-> o.getStatus()).orElse(null);
    }

    @ApiModelProperty("热更新包")
    public String getWgtUrl(){
        return Optional.ofNullable(appVersion).map(o-> o.getWgtUrl()).orElse(null);
    }

    @ApiModelProperty("更新方式 APK WGT")
    @JSONField(serializeUsing = EnumSerializer.class, deserializeUsing = EnumDeserializer.class)
    public AppVersion.UpdateMethod getUpdateMethod(){
        return Optional.ofNullable(appVersion).map(o-> o.getUpdateMethod()).orElse(null);
    }

    @ApiModelProperty("是否强制 yes no")
    @JSONField(serializeUsing = EnumSerializer.class, deserializeUsing = EnumDeserializer.class)
    public AppVersion.IsForce getIsForce(){
        return Optional.ofNullable(appVersion).map(o-> o.getIsForce()).orElse(null);
    }
}
